//
//  YDKeyedArchiver.m
//  YDBASE
//
//  Created by rowena on 2019/4/29.
//  Copyright © 2019年 wuyezhiguhun. All rights reserved.
//

#import "YDKeyedArchiver.h"

@implementation YDKeyedArchiver

/**
 * 归档
 * @pram rootObject 归档内容
 * @pram fileName 归档内容的文件名
 * @return 归档是否成功
 */
+ (BOOL)archiveRootObject:(id)rootObject toFileName:(NSString *)fileName {
    NSString *filePath = [NSString stringWithFormat:@"%@%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0], fileName];
    
    return [NSKeyedArchiver archiveRootObject:rootObject toFile:filePath];
}

/**
 * 接档
 * @pram fileName 接档文件名
 * @return 返回接档出来的数据
 */
+ (id)unarchiveObjectWithFileName:(NSString *)fileName {
    NSString *filePath = [NSString stringWithFormat:@"%@%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0], fileName];
    
    return [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
}

@end
